package com.example.canalclientsync.mapstruct;

import com.example.canalclientsync.canal.po.Dir;
import com.example.canalclientsync.canal.po.VirtualModel;
import com.example.canalclientsync.es.document.EsModel;
import com.example.canalclientsync.es.enums.EsModelClassificationEnum;
import com.newdim.essearchinf.enums.EsModelKindEnum;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
 * @author chen.cr
 * @since 2023/9/15
 */
@Mapper
public interface ModelMapping {
    ModelMapping INSTANCE = Mappers.getMapper(ModelMapping.class);

    default EsModel model2EsModel(VirtualModel model, Dir parentDir) {
        EsModel esModel = new EsModel();
        esModel.setId(model.getModelId());
        esModel.setTenantId(model.getTenantId());

        esModel.setClassification(EsModelClassificationEnum.getFromDir(parentDir).getCode());
        esModel.setKind(EsModelKindEnum.getFromExtension(model.getExtension()).getCode());

        esModel.setModelId(model.getModelId());
        esModel.setMasterId(model.getMasterId());
        esModel.setName(model.getName());
        esModel.setExtension(model.getExtension());
        esModel.setVersion(model.getVersion().toString());
        esModel.setSize(model.getModelSize());
        esModel.setDetaiImg(model.getDetaiImg());
        esModel.setScreenshot(model.getScreenshot());
        esModel.setOssUrl(model.getOssUrl());
        esModel.setLatest(model.getLatested() == 1);
        esModel.setIsFolder(false);

        esModel.setCreateTime(model.getCreateTime());
        esModel.setCreateUserId(model.getCreateUserId());
        esModel.setLastUpdateTime(model.getUpdateTime());
        esModel.setLastUpdateUserId(model.getUpdateUserId());
        esModel.setOwnerUserId(model.getOwnerId());

        esModel.setOriginType(model.getOriginType());
        esModel.setParentDir(parentDir);

        return esModel;
    }


}
